#include "lineitem.h"

LineItem::LineItem(GraphWidget *graphWidget, QPointF p1, QPointF p2) :
    graph(graphWidget),
    startPoint(p1),
    endPoint(p2)
{
}

void LineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    QPen pen;
    pen.setColor(Qt::black);
    pen.setWidth(2);
    painter->setPen(pen);
    painter->setBrush(Qt::NoBrush);
    painter->drawLine(startPoint, endPoint);
}

QRectF LineItem::boundingRect() const
{
//    qreal adjust = ADJUST;
    qreal left = startPoint.x() < endPoint.x() ? startPoint.x(): endPoint.x();
    qreal top = startPoint.y() < endPoint.y() ? startPoint.y(): endPoint.y();
    qreal width = qAbs(startPoint.x() - endPoint.x());
    qreal height = qAbs(startPoint.y() - endPoint.y());
    return QRectF(left, top, width, height).normalized();
}
